//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	SecurableTypeContext.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;

namespace Smart.Common.Security
{
	/// <summary>
	/// Create security context for security type
	/// </summary>
	public class SecurableTypeContext : DisposableBase
	{
		public SecurableType SecurableType;

		/// <summary>
		/// Create security context for security type
		/// </summary>
		public SecurableTypeContext(SecurableType securableType)
		{
			if (securableType == null) throw new ArgumentNullException("securableType");

			SecurableType = securableType;
			SecurableType.EnterSecurityContext();
		}

		/// <summary>
		/// Dispose managed resources. Method called only once.
		/// </summary>
		protected override void DisposeManaged()
		{
			if (SecurableType != null)
			{
				SecurableType.LeaveSecurityContext();
				SecurableType = null;
			}
		}

		/// <summary>
		/// Dispose unmanaged resources. Method called only once.
		/// </summary>
		protected override void DisposeUnmanaged()
		{
		}
	}
}